package com.hsp_java.Homework;

import java.util.ArrayList;
import java.util.Collections;

@SuppressWarnings({"all"})
public class Homework01 {
    public static void main(String[] args) {
        News n1 = new News("新冠确诊病例超千万,数百万印度教徒赴恒河“圣yu”, 引民众担忧");
        News n2 = new News("sdfsjdkfjslkdfksdfsdf");

        ArrayList list = new ArrayList();
        list.add(n1);
        list.add(n2);

        for(int i = list.size() - 1; i >= 0; i--) {
            System.out.println(list.get(i));
        }


        Collections.reverse(list);
        for (Object o : list) {
            System.out.println(o);
        }


    }
}

class News {
    private String title;
    private String main;

    public String getTitle() {
        return title;
    }

    public String getMain() {
        return main;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setMain(String main) {
        this.main = main;
    }

    public News(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        if (title.length() > 15) {
            return "News{" +
                    "title='" + title.substring(0, 14) + "..." + '\'' +
                    '}';
        } else {
            return "News{" +
                    "title='" + title  + '\'' +
                    '}';
        }

    }
}
